from google.appengine.ext import db
from xmw.db import counter
import xmw

class MailTask(db.Model):
    subject =   db.StringProperty()
    content =   db.TextProperty()
    lst_recepts =db.StringListProperty()
    seq     =   db.IntegerProperty()
    is_finished =db.BooleanProperty(default=False)
    
    def save(self):
        self.put()
class MailRecord(db.Model):
    seq=db.IntegerProperty()
    subject = db.StringProperty()
    lst_recepts = db.StringListProperty(default=[])
    date=db.DateTimeProperty( )
    
    def find_recepts(self,recept):
        
        for r in self.lst_recepts:
            if r == recept:
                return True
        
        return False
     
    def save(self):
        self.date = xmw.get_cn_now_time()
        self.put()
    
class MailTaskCounterShard(db.Model):
    """
    to count MailTask.seq
    """    
    count = db.IntegerProperty(required=True, default=0)

class MailCounterShard(db.Model):
    """
    to count MailTaskCounter
    """    
    count = db.IntegerProperty(required=True, default=0)

#mailed Counter used to mark the mailed PostTask
class MailTaskCounter(counter.Counter):
    NUM_SHARDS  =2
    Shard       =MailTaskCounterShard    

#mailed Counter used to mark the mailed PostTask
class MailCounter(counter.Counter):
    NUM_SHARDS  =2
    Shard       =MailCounterShard     